home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / lang / fpcsrc.lha / fpc / compiler / gdb.pas < prev    next >
Pascal/Delphi Source File  |  1998-09-24  |  7KB  |  269 lines

  1. {
  2.     $Id: gdb.pas,v 1.1.1.1 1998/03/25 11:18:13 root Exp $
  3.     Copyright (c) 1996-98 by Florian Klaempfl
  4.  
  5.     This units contains special support for the GDB
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  
  21.  ****************************************************************************
  22. }
  23. unit gdb;
  24.  
  25.   interface
  26.  
  27.     uses
  28. {$ifdef i386}
  29.        i386,
  30. {$endif i386}
  31.        strings,cobjects,globals,aasm;
  32.  
  33.     {stab constants }
  34. Const
  35.     N_GSYM = $20;
  36.     N_STSYM = 38; {initialized const }
  37.     N_LCSYM = 40; {non initialized variable}
  38.     N_Function = $22; {function or const }
  39.     N_TextLine = $44;
  40.     N_DataLine = $46;
  41.     N_BssLine = $48;
  42.     N_RSYM = $40; { register variable }
  43.     N_LSYM = $80;
  44.     N_PSYM = 160;
  45.     N_SourceFile = $64;
  46.     N_IncludeFile = $84;
  47.     N_BINCL = $82;
  48.     N_EINCL = $A2;
  49.     N_EXCL  = $C2;
  50.  
  51.     type
  52.        pai_stabs = ^tai_stabs;
  53.  
  54.        tai_stabs = object(tai)
  55.           str : pchar;
  56.           constructor init(_str : pchar);
  57.           destructor done; virtual;
  58.        end;
  59.  
  60.        pai_stabn = ^tai_stabn;
  61.  
  62.        tai_stabn = object(tai)
  63.           str : pchar;
  64.           constructor init(_str : pchar);
  65.           destructor done; virtual;
  66.        end;
  67.  
  68.        pai_stab_function_name = ^tai_stab_function_name;
  69.  
  70.        tai_stab_function_name = object(tai)
  71.           str : pchar;
  72.           constructor init(_str : pchar);
  73.           destructor done; virtual;
  74.        end;
  75.  
  76. const          DBX_counter : plongint = nil;
  77.                do_count_dbx : boolean = false;
  78.            { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi",
  79.             "eip", "ps", "cs", "ss", "ds", "es", "fs", "gs", }
  80.            { this is the register order for GDB }
  81.  
  82. {$ifdef i386}
  83.        {tregister = (R_NO,R_EAX,R_ECX,R_EDX,R_EBX,R_ESP,R_EBP,R_ESI,R_EDI,
  84.                     R_AX,R_CX,R_DX,R_BX,R_SP,R_BP,R_SI,R_DI,
  85.                     R_AL,R_CL,R_DL,R_BL,R_AH,R_CH,R_BH,R_DH,
  86.                      for an easier assembler generation
  87.                     R_DEFAULT_SEG,R_CS,R_DS,R_ES,R_FS,R_GS,R_SS,
  88.                     R_ST,R_ST0,R_ST1,R_ST2,R_ST3,R_ST4,R_ST5,R_ST6,R_ST7); }
  89.            GDB_i386index : array[tregister] of shortint =
  90.            (-1,0,1,2,3,4,5,6,7,0,1,2,3,4,5,7,0,1,2,3,0,1,2,3,
  91.            -1,10,12,13,14,15,11,
  92.            -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
  93.            { I think, GDB doesn't know MMX (FK) }
  94.            -1,-1,-1,-1,-1,-1,-1,-1);
  95. {$endif i386}
  96.  
  97.   implementation
  98.  
  99. {$IfDef DBX}
  100.  
  101. { to use N_EXCL we have to count the character in the stabs for
  102. N_BINCL to N_EINCL
  103.   Code comes from stabs.c for ld
  104.       if (type == N_BINCL)
  105.     (
  106.       bfd_vma val;
  107.       int nest;
  108.       bfd_byte *incl_sym;
  109.       struct stab_link_includes_entry *incl_entry;
  110.       struct stab_link_includes_totals *t;
  111.       struct stab_excl_list *ne;
  112.  
  113.       val = 0;
  114.       nest = 0;
  115.       for (incl_sym = sym + STABSIZE;
  116.            incl_sym < symend;
  117.            incl_sym += STABSIZE)
  118.         (
  119.           int incl_type;
  120.  
  121.           incl_type = incl_sym[TYPEOFF];
  122.           if (incl_type == 0)
  123.         break;
  124.           else if (incl_type == N_EINCL)
  125.         (
  126.           if (nest == 0)
  127.             break;
  128.           --nest;
  129.         )
  130.           else if (incl_type == N_BINCL)
  131.         ++nest;
  132.           else if (nest == 0)
  133.         (
  134.           const char *str;
  135.  
  136.           str = ((char *) stabstrbuf
  137.              + stroff
  138.              + bfd_get_32 (abfd, incl_sym + STRDXOFF));
  139.           for (; *str != '\0'; str++)
  140.             (
  141.               val += *str;
  142.               if (*str == '(')
  143.             (
  144.                Skip the file number.
  145.               ++str;
  146.               while (isdigit ((unsigned char) *str))
  147.                 ++str;
  148.               --str;
  149.             )
  150.             )
  151.         )
  152.         ) }
  153.  
  154.  
  155.    procedure count_dbx(st : pchar);
  156.      var i : longint;
  157.          do_count : boolean;
  158.      begin
  159.      do_count := false;
  160.      if dbx_counter = nil then
  161.      else
  162.        begin
  163. {$IfDef ExtDebug }
  164.         Comment(V_Info,'Counting '+st);
  165.         Comment(V_Info,'count =  '+tostr(dbx_counter^));
  166.         Comment(V_Info,'addr = '+tostr(longint(dbx_counter)));
  167. {$EndIf ExtDebug }
  168.           for i:=0 to strlen(st) do
  169.             begin
  170.                if st[i] = '"' then
  171.                  if do_count then exit
  172.                  else do_count := true
  173.                else
  174.                if do_count then
  175.                  begin
  176.                    dbx_counter^ := dbx_counter^+byte(st[i]);
  177.                    if st[i] = '(' then
  178.                      begin
  179.                         inc(i);
  180.                         while st[i] in ['0'..'9'] do inc(i);
  181.                         dec(i);
  182.                      end;
  183.                  end;
  184.             end;
  185.        end;
  186.      end;
  187.  
  188. {$EndIf DBX}
  189.  
  190.     constructor tai_stabs.init(_str : pchar);
  191.  
  192.       begin
  193.          inherited init;
  194.          typ:=ait_stabs;
  195.          str:=_str;
  196. {$IfDef DBX}
  197.          if do_count_dbx then
  198.            begin
  199.               count_dbx(str);
  200.               do_count_dbx := false;
  201.            end;
  202. {$EndIf DBX}
  203.       end;
  204.  
  205.     destructor tai_stabs.done;
  206.  
  207.       begin
  208.          strdispose(str);
  209.          inherited done;
  210.       end;
  211.  
  212.     constructor tai_stabn.init(_str : pchar);
  213.  
  214.       begin
  215.          inherited init;
  216.          typ:=ait_stabn;
  217.          str:=_str;
  218.       end;
  219.  
  220.     destructor tai_stabn.done;
  221.  
  222.       begin
  223.          strdispose(str);
  224.          inherited done;
  225.       end;
  226.  
  227.     constructor tai_stab_function_name.init(_str : pchar);
  228.  
  229.       begin
  230.          inherited init;
  231.          typ:=ait_stab_function_name;
  232.          str:=_str;
  233.       end;
  234.  
  235.     destructor tai_stab_function_name.done;
  236.  
  237.       begin
  238.          strdispose(str);
  239.          inherited done;
  240.       end;
  241. end.
  242.  
  243. {
  244.   $Log: gdb.pas,v $
  245.   Revision 1.1.1.1  1998/03/25 11:18:13  root
  246.   * Restored version
  247.  
  248.   Revision 1.5  1998/03/10 01:17:18  peter
  249.     * all files have the same header
  250.     * messages are fully implemented, EXTDEBUG uses Comment()
  251.     + AG... files for the Assembler generation
  252.  
  253.   Revision 1.4  1998/03/02 01:48:33  peter
  254.     * renamed target_DOS to target_GO32V1
  255.     + new verbose system, merged old errors and verbose units into one new
  256.       verbose.pas, so errors.pas is obsolete
  257.  
  258.   Revision 1.3  1998/02/13 10:35:01  daniel
  259.   * Made Motorola version compilable.
  260.   * Fixed optimizer
  261.  
  262.   Revision 1.2  1997/11/28 18:14:32  pierre
  263.    working version with several bug fixes
  264.  
  265.   Revision 1.1.1.1  1997/11/27 08:32:56  michael
  266.   FPC Compiler CVS start
  267.  
  268. }
  269.